package ACWing.TheNnderlyingAlgorithm.快排;
//786. 第k个数

import java.util.Arrays;
import java.util.Scanner;

/**
 * @author :chenjie
 * @date :Created 2022/11/16 22:59
 */
public class K_digit {
    public static void main(String[] args) {
        Scanner sc=new Scanner(System.in);
        int n=sc.nextInt();
        int x=sc.nextInt();
        int[]arr=new int[n];
        for (int i = 0; i < n; i++) {
            arr[i]=sc.nextInt();
        }
        sort(0,n-1,arr);
        System.out.println(Arrays.toString(arr));
        System.out.println(arr[n-x]);
    }
    public static void sort(int l,int r,int[]arr){
        if(l>=r){
            return;
        }
        int i=l-1,j=r+1,mid=arr[l+r>>1];//根据数的大小将数组划分为俩段
        while (i<j){
            do {
                i++;
            }while (arr[i]<mid);
            do {
                j--;
            }while (arr[j]>mid);
            if(i<j){
                int temp=arr[j];
                arr[j]=arr[i];
                arr[i]=temp;

            }
        }
        sort(l,j,arr);
        sort(j+1,r,arr);
    }
}
